package yogiro.controller;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import yogiro.service.NoticeCommentService;
import yogiro.to.NoticeCommentTO;


public class NoticeCommentController extends MultiActionController{
	private NoticeCommentService service;
	
	public void setNoticeCommentService(NoticeCommentService service){
		this.service = service;
	}
	public NoticeCommentController(){}
	//삽입하는 메소드
	public ModelAndView insertComment(HttpServletRequest request, HttpServletResponse response){
		//1. 찾아오는 문제 ==글게시판의 글넘버랑 코맨트게시판의 글넘버랑 같을때만 가져옴 ㅠ (결국 셀렉트문)
		//2. 삽입시 글넘버 못찾아옴 ㅠ
		//3. 델리트시 글게시판의 넘버로 지우면 forign key 의 값들도 저절로 삭제하는법좀.ㅠ

		String content = request.getParameter("content");
		String id = request.getParameter("id");
		System.out.println("1"+content);
		System.out.println("2"+id);
		int noticeNo=Integer.parseInt(request.getParameter("noticeNo"));
		System.out.println(noticeNo);
		ModelAndView mv = null;
		
		try {
			
			NoticeCommentTO cto = service.insertComment(content, id,noticeNo);
			System.out.println("추가된후 cto란?"+cto);
			cto.setCommentContent(service.replace(cto.getCommentContent()));
			
			mv = new ModelAndView("jsonView","result",cto);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return mv;
	}
	
	
}


